import { HintBtnView } from "../mapUI/HintBtnView";
import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../extend/language/Language";
import { LayerManager } from "../../manager/LayerManager";
import { RightTopLayerLine } from "../../manager/RightTopLayerLine";
import { RightTopLayerIndex } from "../../manager/RightTopLayerIndex";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { DailyRule } from "../../rules/DailyRule";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelType } from "../../scene/modle/data/ModelType";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { ActionType } from "../../scene/modle/data/ActionType";
import { SWFInfo } from "../../../../com/gengine/resource/info/SWFInfo";
import { Global } from "../../../../com/gengine/global/Global";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
type int = number;
//class DailyIconSwf
    
    export  class DailyIconSwf extends HintBtnView implements IToolTipItem
    {
        constructor()
        {
            super();
            if (DailyIconSwf._instance) 
            {
                throw new Error("DailyIconSwf.as single model");
            }
            this.toolTipData = HTMLUtil.addColor(Language.getString(20955), "#ff00ff");
            this.buttonMode = true;
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            layer = LayerManager.rightTopUILayer;
            this.line = RightTopLayerLine.lineOne;
            this.index = RightTopLayerIndex.DailyIcon;
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.FirstRechargeGiftOpen, DailyRule.GiftGet));
            return;
        }

        /* internal  */initSwf(): void
        {
            if (!this._dailyIcon) 
            {
                this._dailyIcon = new SWFPlayer();
                this._dailyIcon.loadComplete = this.onDailyLoadedHandler;
            }
            if (!this._dailyIcon.parent) 
            {
                addChild(this._dailyIcon);
            }
            this._dailyIcon.load("dailyIcon.swf", ModelType.Item, null);
            return;
        }

        /* internal  */initEffectSwf(): void
        {
            if (!this._effectMc) 
            {
                LoaderManager.instance.load("firstRechargeEffect.swf", this.onLoaded);
            }
            return;
        }

        /* internal  */initBtn(): void
        {
            if (!this._loadedBtn) 
            {
                this._loadedBtn = ObjCreate.createGLoadedButton(ResFileConst.FirstRecharge, 0, 0, 60, 50, this);
            }
            return;
        }

        /* internal  */onDailyLoadedHandler(arg1: SWFPlayer): void
        {
            this._dailyIcon.updateFrame(ActionType.Stand, 1, true);
            this._dailyIcon.updateCurrentFrame(0);
            this._dailyIcon.play();
            return;
        }

        /* internal  */onLoaded(arg1: SWFInfo): void
        {
            this._effectMc = arg1.clip;
            this._effectMc.x = -170;
            this._effectMc.y = -180;
            addChild(this._effectMc);
            this._effectMc.play();
            return;
        }

        /* internal  */onStageResizeHandler(arg1: DataEvent=null): void
        {
            this.y = 7;
            this.x = Global.stage.stageWidth - 180 - 60;
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            this.initBtn();
            this.initEffectSwf();
            super.show(arg1, arg2);
            return;
        }

        public /* override */ hide(): void
        {
            if (this._dailyIcon) 
            {
                if (this._dailyIcon.parent) 
                {
                    removeChild(this._dailyIcon);
                }
                this._dailyIcon.dispose();
            }
            if (this._effectMc) 
            {
                if (this._effectMc.parent) 
                {
                    removeChild(this._effectMc);
                }
                this._effectMc.stop();
            }
            super.hide();
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResizeHandler);
            return;
        }

        public get toolTipData()
        {
            return this._tooltipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._tooltipData = arg1;
            return;
        }

        public static getInstance(): DailyIconSwf
        {
            if (!DailyIconSwf._instance) 
            {
                DailyIconSwf._instance = new DailyIconSwf();
            }
            return DailyIconSwf._instance;
        }

        /* internal */ /* var */_dailyIcon: SWFPlayer;

        /* internal */ /* var */_loadedBtn: GLoadedButton;

        /* internal */ /* var */_effectMc: Object /* flash.display.MovieClip */;

        /* internal */ /* var */_tooltipData;

        /* internal */ static /* var */_instance: DailyIconSwf;
    }
